// Write your cade below:
function getRandomIntInclusive(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min + 1)) + min; 
  }//产生一个随机数

function getRandom(){
    let  random = getRandomIntInclusive(1000,9999); 
     random = random.toString();
    for(let i =0;i<4;i++){
        if(random.lastIndexOf(random[i]) !== i){
            random = getRandom();
        }
    }
   return random;
}//产生一个不重复的随机数


function  toArr(number){
    let str = number.toString();
    let result = str.split("");
    return result;
}//将数字转换为数组字符串

function input(){
    var readlineSync = require('readline-sync');
    var input = readlineSync.question('produce a four-digit random ');
     return input;
}//获取输入的数

function main(system_num,input_num){
     let system_arr = toArr(system_num);
     let input_arr = toArr(input_num);
    let countA=0,countB=0;
        for(let i = 0;i<system_arr.length;i++){
            for(let j = 0;j<input_arr.length;j++){
                if(system_arr[i] === input_arr[j]){
                    countB ++ ;
                }
                if(system_arr[i] === input_arr[j]&&i === j){
                    countA++;
                    countB--;
                    }
            }
        }
    let str = '';
    str +=`${countA}A${countB}B`;
    return str;
}

    let  num = getRandom();  
    let system_arr = toArr(num);
    console.log(system_arr);
    let intNum = input();
    let input_arr = toArr(intNum);
    console.log(input_arr);
    let str = main(system_arr,input_arr);
    console.log(str);
    module.exports = { main,toArr};


